<template>
  <div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="供应商">
              <a-input placeholder="请输入供应商名称" v-model="queryParam.supplyFullName"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <a-table
      ref="table"
      size="middle"
      :scroll="{x:true}"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange">

      <template slot="htmlSlot" slot-scope="text">
        <div v-html="text"></div>
      </template>
      <template slot="imgSlot" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
        <img v-else :src="getImgView(text)" height="25px" alt=""
             style="max-width:80px;font-size: 12px;font-style: italic;"/>
      </template>
      <template slot="pcaSlot" slot-scope="text">
        <div>{{ getPcaText(text) }}</div>
      </template>
      <template slot="supplyFullName" slot-scope="text, record">
        <a @click="handleDetail(record)">
          <j-ellipsis :value="text" :length="12"/>
        </a>
      </template>
      <template slot="address" slot-scope="text, record">
        <j-ellipsis :value="text" :length="12"/>
      </template>
      <template slot="cateScope" slot-scope="text, record">
        <j-ellipsis :value="text" :length="12"/>
      </template>
      <template slot="remark" slot-scope="text, record">
        <j-ellipsis :value="text" :length="12"/>
      </template>
      <template slot="fileSlot" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button
          v-else
          :ghost="true"
          type="primary"
          icon="download"
          size="small"
          @click="downloadFile(text)">
          下载
        </a-button>
      </template>

    </a-table>
  </div>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import Area from '@/components/_util/Area'
import {getAction} from "@/api/manage";

export default {
  name: 'MmSupplyMaterialTable',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  props: {
    initQueryParam: {},
  },
  data() {
    return {
      description: '采购供应商物料统计列表',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '供应商名称',
          align: "center",
          dataIndex: 'supplyFullName',
          scopedSlots: {customRender: 'materialDesc'},
        },
        {
          title: '采购次数',
          align: "center",
          dataIndex: 'buyCount',
          width: 100,
        },
        {
          title: '采购总额',
          align: "center",
          dataIndex: 'buyMoney',
          width: 100,
        },
        {
          title: '最近采购日期',
          align: "center",
          dataIndex: 'lastBuyDate',
          width: 100,
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '省市区',
          align: "center",
          dataIndex: 'administrativeArea',
          scopedSlots: {customRender: 'pcaSlot'},
          width: 200
        },
        {
          title: '详细地址',
          align: "center",
          dataIndex: 'address',
          width: 240,
          scopedSlots: {customRender: 'address'}
        },
        {
          title: '成立时间',
          align: "center",
          dataIndex: 'setTime',
          width: 100,
          customRender: function (text) {
            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '注册资金',
          align: "center",
          dataIndex: 'registCapital',
          width: 100
        },
        {
          title: '网址',
          align: "center",
          dataIndex: 'webSite',
          width: 140
        },
        {
          title: '供应商类型',
          align: "center",
          width: 100,
          dataIndex: 'supplyType_dictText'
        },
        {
          title: '经营范围',
          align: "center",
          dataIndex: 'cateScope',
          width: 140,
          scopedSlots: {customRender: 'cateScope'}
        },
        {
          title: '行业',
          align: "center",
          width: 100,
          dataIndex: 'cateTypeCode_dictText'
        },
        {
          title: '企业性质',
          align: "center",
          width: 100,
          dataIndex: 'entTypeCode_dictText'
        },
        {
          title: '备注',
          align: "center",
          dataIndex: 'remark',
          width: 200,
          scopedSlots: {customRender: 'remark'}
        },
      ],
      url: {
        list: "/mm/purchaseOrder/supplyMaterialStatList",
      },
      dictOptions: {},
      pcaData: '',
      superFieldList: [],
    }
  },
  created() {
    this.pcaData = new Area()
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    getPcaText(code) {
      return this.pcaData.getText(code);
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'supplyNo', text: '供应商编码', dictCode: ''})
      fieldList.push({type: 'string', value: 'supplyFullName', text: '供应商名称', dictCode: ''})
      fieldList.push({type: 'string', value: 'supplyShortName', text: '供应商简称', dictCode: ''})
      fieldList.push({type: 'string', value: 'address', text: '详细地址', dictCode: ''})
      fieldList.push({type: 'date', value: 'setTime', text: '成立时间'})
      fieldList.push({type: 'BigDecimal', value: 'registCapital', text: '注册资金', dictCode: ''})
      fieldList.push({type: 'string', value: 'webSite', text: '网址', dictCode: ''})
      fieldList.push({type: 'string', value: 'supplyType', text: '供应商类型', dictCode: 'mdm_supply_type'})
      fieldList.push({type: 'string', value: 'cateScope', text: '经营范围', dictCode: ''})
      fieldList.push({type: 'string', value: 'cateTypeCode', text: '行业', dictCode: 'crm_cust_cate'})
      fieldList.push({type: 'string', value: 'entTypeCode', text: '企业性质', dictCode: 'crm_ent_type'})
      fieldList.push({type: 'string', value: 'invBankNo', text: '银行账号', dictCode: ''})
      fieldList.push({type: 'string', value: 'invBankName', text: '开户银行', dictCode: ''})
      fieldList.push({type: 'string', value: 'invTaxNo', text: '纳税人识别号', dictCode: ''})
      fieldList.push({type: 'string', value: 'invAddr', text: '地址', dictCode: ''})
      fieldList.push({type: 'string', value: 'invTel', text: '电话', dictCode: ''})
      fieldList.push({type: 'pca', value: 'administrativeArea', text: '省市区'})
      fieldList.push({type: 'string', value: 'remark', text: '备注', dictCode: ''})
      this.superFieldList = fieldList
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      Object.assign(this.queryParam, this.initQueryParam);
      var params = this.getQueryParams();//查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result;
          if (res.result.total) {
            this.ipagination.total = res.result.total;
          } else {
            this.ipagination.total = 0;
          }
          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>